package com.person.jiaiplan.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.person.jiaiplan.assembler.AchievementLogsAssembler;
import com.person.jiaiplan.pojo.R;
import com.person.jiaiplan.pojo.dto.AchievementQueryReqDTO;
import com.person.jiaiplan.pojo.dto.AchievementQueryResDTO;
import com.person.jiaiplan.pojo.entity.AchievementLogs;
import com.person.jiaiplan.service.AchievementLogsService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 成果日志
 */
@AllArgsConstructor
@RestController
@RequestMapping("achievement")
@Validated
public class AchievementLogsController {

    @Autowired
    private AchievementLogsService achievementLogsService;

    /**
     * 成果查询
     *
     * @param
     * @return
     */
    @GetMapping("query")
    public R<List<AchievementQueryResDTO>> query(@RequestParam(name = "scheduleId") String scheduleId) {
        List<AchievementLogs> achievementLogs = achievementLogsService.list(Wrappers.<AchievementLogs>lambdaQuery().eq(AchievementLogs::getScheduleId, scheduleId));
        return R.ok(AchievementLogsAssembler.INSTANCE.toAchievementQueryReqDTOList(achievementLogs));
    }


    /**
     * 成果添加
     *
     * @param
     * @return
     */
    @PostMapping("add")
    public R<Boolean> addAchievementLog(AchievementQueryReqDTO reqDTO) {
        AchievementLogs achievementLogs = AchievementLogsAssembler.INSTANCE.toAchievementLogs(reqDTO);
        return R.ok(achievementLogsService.save(achievementLogs));
    }


}
